import pygame
from pygame.sprite import DirtySprite
from events import Events

class Button(DirtySprite):
	def __init__(self, image_path, image_path_2, image_path_3):
		DirtySprite.__init__(self)

		self.image = pygame.image.load(image_path)
		self.image1 = self.image #default
		self.image2 = pygame.image.load(image_path_2)	#Mouse over
		self.image3 = pygame.image.load(image_path_3)	#Mouse pressed
	
		self.rect = self.image.get_rect()

		self.pressed = False
		self.clicked = False

	def isClicked(self):
		if self.clicked == True:
			self.clicked = False
			return True
		return False

	def update(self):
		if not self.rect.collidepoint(pygame.mouse.get_pos()) and self.image != self.image1:	#Mouse Out
			self.image = self.image1
			self.pressed = False
			#print "out"
			return None

		for event in Events.events:
			if event.type == pygame.MOUSEBUTTONUP and self.rect.collidepoint(pygame.mouse.get_pos()) and self.pressed:
				self.image = self.image1
				self.pressed = False
				self.clicked = True
				#print "up"
			elif event.type == pygame.MOUSEBUTTONDOWN and self.rect.collidepoint(pygame.mouse.get_pos()) and self.image != self.image3:
				self.image = self.image3
				self.pressed = True
				#print "pressed"
				
		if self.rect.collidepoint(pygame.mouse.get_pos()) and not self.pressed and self.image != self.image2:	#Mouse Over
			self.image = self.image2
			#print "over"

